/**
 * @author Matan Mizrahi,Chen weissman
 * Introduction to computer science, assingment5
 * Date:2.1.2011
 * 
 * LongSum class, in which extends addition class, represents long adding expressions.
 * (e.g a+b when a and b are complicated expressions such as multiplication, addition etc. 
 */
public class LongSum extends CompoundExpression{
	//*********************************Fields************************************//
	private Expression [] addEx;
	
    //*********************************Constructors******************************//
    /**
     * Constructor that creates a longSum expression of composed of the two expressions
     *
     * @param addEx  the expression array that contains all the expressions
     * @throws RuntimeException for null input expressions
     */
	public LongSum(Expression[] addEx){
		 super(addEx);
	}
	//**********************************Methods*******************************//
    /**
     * Returns the last operation symbol of Addition Expression
     *
     * @return String "SIGMA" in which represents the last operation
     */
    public String getLastOperationSymbol() {
        return "SIGMA";
    }
	/**
	 * 
	 * Evaluates the expression given an assignment. 
	 * @param assign the given assignment.
	 * @return The value of this expression with respect
	 * to the given assignment. Any variable in the expression 
	 * which is not assigned with a value under the assignment
	 * {@code assign} will be considered as a variable which
	 * value is 0.
	 * @throws Exception  in case the assignment is null or if the variable is not assigned to a value
	 */
	public double evaluate(Assignment assign) throws Exception{
		double ans=0;
		if (assign==null)
			throw new NullPointerException("LongSum method evaluate got a null argument.");
		else
		for (int i=0;i<addEx.length;i=i+1)
			ans=ans+addEx[i].evaluate(assign);
		return ans;
	}
	
	/**
	 * 
	 * Derivative operation on Expression according to varName.
	 * @param varName the name of the variable according to which
	 * the expression is derived.
	 * @return New expression representing the derivative of this expression.
	 */
	@SuppressWarnings("null")
	public Expression derivative(char varName){
	CompoundExpression  ans;
	Expression[] derivedArr=null;
	for	(int i=0;i<addEx.length;i++)
		derivedArr[i]=addEx[i].derivative(varName);
	ans=new LongSum(derivedArr);
	return ans;
	}


}


